home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 April / CHIP 1996 aprilis (CD06).zip / CHIP_CD06.ISO / microsft / vb4 / vb4-3.cab / calc.frm < prev    next >
Text File  |  1995-08-15  |  11KB  |  356 lines

  1. VERSION 4.00
  2. Begin VB.Form Calculator 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Calculator"
  5.    ClientHeight    =   2970
  6.    ClientLeft      =   2580
  7.    ClientTop       =   1485
  8.    ClientWidth     =   3270
  9.    ClipControls    =   0   'False
  10.    BeginProperty Font 
  11.       name            =   "System"
  12.       charset         =   1
  13.       weight          =   700
  14.       size            =   9.75
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    Height          =   3375
  20.    Icon            =   "CALC.frx":0000
  21.    Left            =   2520
  22.    LinkMode        =   1  'Source
  23.    LinkTopic       =   "Form1"
  24.    MaxButton       =   0   'False
  25.    ScaleHeight     =   2970
  26.    ScaleWidth      =   3270
  27.    Top             =   1140
  28.    Width           =   3390
  29.    Begin VB.CommandButton Number 
  30.       Caption         =   "7"
  31.       Height          =   480
  32.       Index           =   7
  33.       Left            =   120
  34.       TabIndex        =   7
  35.       Top             =   600
  36.       Width           =   480
  37.    End
  38.    Begin VB.CommandButton Number 
  39.       Caption         =   "8"
  40.       Height          =   480
  41.       Index           =   8
  42.       Left            =   720
  43.       TabIndex        =   8
  44.       Top             =   600
  45.       Width           =   480
  46.    End
  47.    Begin VB.CommandButton Number 
  48.       Caption         =   "9"
  49.       Height          =   480
  50.       Index           =   9
  51.       Left            =   1320
  52.       TabIndex        =   9
  53.       Top             =   600
  54.       Width           =   480
  55.    End
  56.    Begin VB.CommandButton Cancel 
  57.       Caption         =   "C"
  58.       Height          =   480
  59.       Left            =   2040
  60.       TabIndex        =   10
  61.       Top             =   600
  62.       Width           =   480
  63.    End
  64.    Begin VB.CommandButton CancelEntry 
  65.       Caption         =   "CE"
  66.       Height          =   480
  67.       Left            =   2640
  68.       TabIndex        =   11
  69.       Top             =   600
  70.       Width           =   480
  71.    End
  72.    Begin VB.CommandButton Number 
  73.       Caption         =   "4"
  74.       Height          =   480
  75.       Index           =   4
  76.       Left            =   120
  77.       TabIndex        =   4
  78.       Top             =   1200
  79.       Width           =   480
  80.    End
  81.    Begin VB.CommandButton Number 
  82.       Caption         =   "5"
  83.       Height          =   480
  84.       Index           =   5
  85.       Left            =   720
  86.       TabIndex        =   5
  87.       Top             =   1200
  88.       Width           =   480
  89.    End
  90.    Begin VB.CommandButton Number 
  91.       Caption         =   "6"
  92.       Height          =   480
  93.       Index           =   6
  94.       Left            =   1320
  95.       TabIndex        =   6
  96.       Top             =   1200
  97.       Width           =   480
  98.    End
  99.    Begin VB.CommandButton Operator 
  100.       Caption         =   "+"
  101.       Height          =   480
  102.       Index           =   1
  103.       Left            =   2040
  104.       TabIndex        =   12
  105.       Top             =   1200
  106.       Width           =   480
  107.    End
  108.    Begin VB.CommandButton Operator 
  109.       Caption         =   "-"
  110.       Height          =   480
  111.       Index           =   3
  112.       Left            =   2640
  113.       TabIndex        =   13
  114.       Top             =   1200
  115.       Width           =   480
  116.    End
  117.    Begin VB.CommandButton Number 
  118.       Caption         =   "1"
  119.       Height          =   480
  120.       Index           =   1
  121.       Left            =   120
  122.       TabIndex        =   1
  123.       Top             =   1800
  124.       Width           =   480
  125.    End
  126.    Begin VB.CommandButton Number 
  127.       Caption         =   "2"
  128.       Height          =   480
  129.       Index           =   2
  130.       Left            =   720
  131.       TabIndex        =   2
  132.       Top             =   1800
  133.       Width           =   480
  134.    End
  135.    Begin VB.CommandButton Number 
  136.       Caption         =   "3"
  137.       Height          =   480
  138.       Index           =   3
  139.       Left            =   1320
  140.       TabIndex        =   3
  141.       Top             =   1800
  142.       Width           =   480
  143.    End
  144.    Begin VB.CommandButton Operator 
  145.       Caption         =   "X"
  146.       Height          =   480
  147.       Index           =   2
  148.       Left            =   2040
  149.       TabIndex        =   14
  150.       Top             =   1800
  151.       Width           =   480
  152.    End
  153.    Begin VB.CommandButton Operator 
  154.       Caption         =   "/"
  155.       Height          =   480
  156.       Index           =   0
  157.       Left            =   2640
  158.       TabIndex        =   15
  159.       Top             =   1800
  160.       Width           =   480
  161.    End
  162.    Begin VB.CommandButton Number 
  163.       Caption         =   "0"
  164.       Height          =   480
  165.       Index           =   0
  166.       Left            =   120
  167.       TabIndex        =   0
  168.       Top             =   2400
  169.       Width           =   1080
  170.    End
  171.    Begin VB.CommandButton Decimal 
  172.       Caption         =   "."
  173.       Height          =   480
  174.       Left            =   1320
  175.       TabIndex        =   18
  176.       Top             =   2400
  177.       Width           =   480
  178.    End
  179.    Begin VB.CommandButton Operator 
  180.       Caption         =   "="
  181.       Height          =   480
  182.       Index           =   4
  183.       Left            =   2040
  184.       TabIndex        =   16
  185.       Top             =   2400
  186.       Width           =   480
  187.    End
  188.    Begin VB.CommandButton Percent 
  189.       Caption         =   "%"
  190.       Height          =   480
  191.       Left            =   2640
  192.       TabIndex        =   17
  193.       Top             =   2400
  194.       Width           =   480
  195.    End
  196.    Begin VB.Label Readout 
  197.       Alignment       =   1  'Right Justify
  198.       BackColor       =   &H0000FFFF&
  199.       BorderStyle     =   1  'Fixed Single
  200.       Caption         =   "0."
  201.       BeginProperty Font 
  202.          name            =   "MS Sans Serif"
  203.          charset         =   1
  204.          weight          =   700
  205.          size            =   12
  206.          underline       =   0   'False
  207.          italic          =   0   'False
  208.          strikethrough   =   0   'False
  209.       EndProperty
  210.       ForeColor       =   &H00000000&
  211.       Height          =   375
  212.       Left            =   120
  213.       TabIndex        =   19
  214.       Top             =   105
  215.       Width           =   3000
  216.    End
  217. End
  218. Attribute VB_Name = "Calculator"
  219. Attribute VB_Creatable = False
  220. Attribute VB_Exposed = False
  221. ' ------------------------------------------------------------------------
  222. '               Copyright (C) 1994 Microsoft Corporation
  223. '
  224. ' You have a royalty-free right to use, modify, reproduce and distribute
  225. ' the Sample Application Files (and/or any modified version) in any way
  226. ' you find useful, provided that you agree that Microsoft has no warranty,
  227. ' obligations or liability for any Sample Application Files.
  228. ' ------------------------------------------------------------------------
  229. Option Explicit
  230. Dim Op1, Op2                ' Previously input operand.
  231. Dim DecimalFlag As Integer  ' Decimal point present yet?
  232. Dim NumOps As Integer       ' Number of operands.
  233. Dim LastInput               ' Indicate type of last keypress event.
  234. Dim OpFlag                  ' Indicate pending operation.
  235. Dim TempReadout
  236.  
  237. ' Click event procedure for C (cancel) key.
  238. ' Reset the display and initializes variables.
  239. Private Sub Cancel_Click()
  240.     ReadOut = Format(0, "0.")
  241.     Op1 = 0
  242.     Op2 = 0
  243.     Form_Load
  244. End Sub
  245.  
  246. ' Click event procedure for CE (cancel entry) key.
  247. Private Sub CancelEntry_Click()
  248.     ReadOut = Format(0, "0.")
  249.     DecimalFlag = False
  250.     LastInput = "CE"
  251. End Sub
  252.  
  253. ' Click event procedure for decimal point (.) key.
  254. ' If last keypress was an operator, initialize
  255. ' readout to "0." Otherwise, append a decimal
  256. ' point to the display.
  257. Private Sub Decimal_Click()
  258.     If LastInput = "NEG" Then
  259.         ReadOut = Format(0, "-0.")
  260.     ElseIf LastInput <> "NUMS" Then
  261.         ReadOut = Format(0, "0.")
  262.     End If
  263.     DecimalFlag = True
  264.     LastInput = "NUMS"
  265. End Sub
  266.  
  267. ' Initialization routine for the form.
  268. ' Set all variables to initial values.
  269. Private Sub Form_Load()
  270.     DecimalFlag = False
  271.     NumOps = 0
  272.     LastInput = "NONE"
  273.     OpFlag = " "
  274.     ReadOut = Format(0, "0.")
  275.     Decimal.Caption = Format(0, ".")
  276. End Sub
  277.  
  278. ' Click event procedure for number keys (0-9).
  279. ' Append new number to the number in the display.
  280. Private Sub Number_Click(Index As Integer)
  281.     If LastInput <> "NUMS" Then
  282.         ReadOut = Format(0, ".")
  283.         DecimalFlag = False
  284.     End If
  285.     If DecimalFlag Then
  286.         ReadOut = ReadOut + Number(Index).Caption
  287.     Else
  288.         ReadOut = Left(ReadOut, InStr(ReadOut, Format(0, ".")) - 1) + Number(Index).Caption + Format(0, ".")
  289.     End If
  290.     If LastInput = "NEG" Then ReadOut = "-" & ReadOut
  291.     LastInput = "NUMS"
  292. End Sub
  293.  
  294. ' Click event procedure for operator keys (+, -, x, /, =).
  295. ' If the immediately preceeding keypress was part of a
  296. ' number, increments NumOps. If one operand is present,
  297. ' set Op1. If two are present, set Op1 equal to the
  298. ' result of the operation on Op1 and the current
  299. ' input string, and display the result.
  300. Private Sub Operator_Click(Index As Integer)
  301.     TempReadout = ReadOut
  302.     If LastInput = "NUMS" Then
  303.         NumOps = NumOps + 1
  304.     End If
  305.     Select Case NumOps
  306.         Case 0
  307.         If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
  308.             ReadOut = "-" & ReadOut
  309.             LastInput = "NEG"
  310.         End If
  311.         Case 1
  312.         Op1 = ReadOut
  313.         If Operator(Index).Caption = "-" And LastInput <> "NUMS" And OpFlag <> "=" Then
  314.             ReadOut = "-"
  315.             LastInput = "NEG"
  316.         End If
  317.         Case 2
  318.         Op2 = TempReadout
  319.         Select Case OpFlag
  320.             Case "+"
  321.                 Op1 = CDbl(Op1) + CDbl(Op2)
  322.             Case "-"
  323.                 Op1 = CDbl(Op1) - CDbl(Op2)
  324.             Case "X"
  325.                 Op1 = CDbl(Op1) * CDbl(Op2)
  326.             Case "/"
  327.                 If Op2 = 0 Then
  328.                    MsgBox "Can't divide by zero", 48, "Calculator"
  329.                 Else
  330.                    Op1 = CDbl(Op1) / CDbl(Op2)
  331.                 End If
  332.             Case "="
  333.                 Op1 = CDbl(Op2)
  334.             Case "%"
  335.                 Op1 = CDbl(Op1) * CDbl(Op2)
  336.             End Select
  337.         ReadOut = Op1
  338.         NumOps = 1
  339.     End Select
  340.     If LastInput <> "NEG" Then
  341.         LastInput = "OPS"
  342.         OpFlag = Operator(Index).Caption
  343.     End If
  344. End Sub
  345.  
  346. ' Click event procedure for percent key (%).
  347. ' Compute and display a percentage of the first operand.
  348. Private Sub Percent_Click()
  349.     ReadOut = ReadOut / 100
  350.     LastInput = "Ops"
  351.     OpFlag = "%"
  352.     NumOps = NumOps + 1
  353.     DecimalFlag = True
  354. End Sub
  355.  
  356.